<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class clear_refund extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'songshu:clear_refund';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '清除排队上线中的已拒绝内容';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $list = DB::table('check_article_queue')->where('exec',0)->orderBy('id','asc')->limit(100)->get()->toArray();
        $video = $article = 0;
        foreach($list as $item){
            if($item->type==0){
                $data = DB::connection('db2')->table('article')->where('id',$item->article_id)->first(['status']);
                if($data->status==2){
                    DB::table('check_article_queue')->where('id',$item->id)->delete();
                    echo "article_id".'=>'.$item->id."\n";
                    $article++;
                }
            }elseif($item->type==1){
                $data = DB::connection('db2')->table('video')->where('id',$item->article_id)->first(['status']);
                if($data->status==2){
                    DB::table('check_article_queue')->where('id',$item->id)->delete();
                    echo "video_id".'=>'.$item->id."\n";
                    $video++;
                }
            }
            
        }
        echo "total_article".'=>'.$article."\n";
        echo "total_video".'=>'.$video."\n";
    }
}
